package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.situ.mall.entity.Cart;
import com.situ.mall.entity.CartProductVO;
import com.situ.mall.mapper.CartMapper;
import com.situ.mall.mapper.CategoryMapper;
import com.situ.mall.service.ICartService;

@Service
public class CartServiceImpl implements ICartService{
	@Autowired
	private CategoryMapper categoryMapper;
	@Autowired
	private CartMapper cartMapper;

	@Override
	public int insertToCart(Cart cart) {
		System.out.println("CartServiceImpl.insertToCart()");
		int isExist = cartMapper.checkExist(cart.getProductId());
		if (isExist > 0) {
			return cartMapper.updateQuantity(cart);
		}
		return cartMapper.insert(cart);
	}

	@Override
	public List<CartProductVO> getCartListPage(Integer id) {
		System.out.println("CartServiceImpl.getCartListPage()");
		
		return cartMapper.getCartListPage(id);
	}

	@Override
	public void deleteByCartId(Integer id) {
		System.out.println("CartServiceImpl.deleteByCartId()");
		cartMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void changeValue(Integer id, Integer count) {
		System.out.println("CartServiceImpl.changeValue()");
		cartMapper.changeValue(id,count);
		
	}
}
